#pragma once
#include "Matrix.h"
//#include "CVSElapsedTimer.h"
#define  FLY_BOX 0
#ifndef GL_MULTISAMPLE
#define GL_MULTISAMPLE  0x809D
#endif
class CVSElapsedTimer;
class CSpreadsheet;
class CData
{
public:
    CData();
    virtual ~CData();

    virtual void load(const vector<CSpreadsheet*> &vSpreadsheet_ );
    virtual void precompute();
    virtual void precomputeEachTrial();
    virtual void afterCompute();
    virtual void clear();
    virtual void updateOutput(int nJoySticky_=0);

    virtual bool allTrialsFinished(); 
    virtual bool trialFinished()  {return true;}     
    virtual bool preRunFinished() {return true;}
    virtual void saveToFile() {};
    virtual void computeEyePositionAndGazing(CMatrix<double>& mEye_,CMatrix<double>& mGazingPoint_,int nCurrentFrame_);
    /*bool waitForTrigger();*/
    //retrievers
    const    vector<double>&      GetBackColor()           const    {return _vBackColor;}
             vector<double>&      setBackColor()                    {return _vBackColor;}
    const    int&                 sceneType()              const    {return _nSceneType;}
    const    float&               gfxFOVy()                const    {return _fFOVy;}
             float&               setGfxFOVy()                      {return _fFOVy;}
    const    float&               gfxFOVx()                const    {return _fFOVx;}
             float&               setGfxFOVx()                      {return _fFOVx;}
    const    float&               gfxNear()                const    {return _fNear;}
             float&               setGfxNear()                      {return _fNear;}
    const    float&               gfxFar()                 const    {return _fFar;}
             float&               setGfxFar()                       {return _fFar;}
    const    float&               gfxAspectRatio()         const    {return _fAspectRatio;}
             float&               setGfxAspectRatio()               {return _fAspectRatio;}
    const    double&              eyeHeight()              const    {return _dEyeHeight;}
             double&              setEyeHeight()                    {return _dEyeHeight;}    
    const    vector<string>&      texFileName()            const    {return _vstrTexFileName;}
             vector<string>&      setTexFileName()                  {return _vstrTexFileName;}
    const    float&               screenWidth()            const    {return _fScreenWidth;}
             float&               setScreenWidth()                  {return _fScreenWidth;}
    const    float&               screenHeight()           const    {return _fScreenHeight;}
             float&               setScreenHeight()                 {return _fScreenHeight;}
    // script file
    const    CMatrix<double>&     GetRunScript()           const    {return _mRunScript;}
             CMatrix<double>&      setRunScript()                    {return _mRunScript;}
    // output file name
    const    string&              outputFileName()         const    {return _strOutputFileName;}
             string&              setOutputFileName()               {return _strOutputFileName;}
    const    int                  timeIdx()                const    {return _nCurrFrameIdx;}
    const    bool&                flyBox()                 const    {return _bFlyboxEnabled;}
             bool&                setFlyBox()                       {return _bFlyboxEnabled;}

    const    int&                 texScale()               const    {return _nTexScale;}
    const    int                  trialIdx()               const    {return _nTrialIdx;}
    //script file name
    const QString&                scriptFileName() const            {return _strScriptFileName;}
          QString&                setScriptFileName()               {return _strScriptFileName;}
    //texture file name
    // frame rate
    int&                          setTexScale()                     {return _nTexScale;}   
    int&                          setTimeIdx()                      {return _nCurrFrameIdx;}
    int&                          setTrialIdx()                     {return _nTrialIdx;}
    // key response
    const double&                 xPosition() const {return _dXPosition;}
          double&                 setXPosition() {return _dXPosition;}

    const string& className() const {return _strClassName;}
    const int& systemOutput() const {return _nSystemOutput;}
          int& setSystemOutput()    {return _nSystemOutput;}
    const int& checkFrameRate() const {return _nCheckFrameRate;}
          int& setCheckFrameRate()    {return _nCheckFrameRate;}
    const int& blockSize()    const {return _nBlockSize;}
          int& setBlockSize()       {return _nBlockSize;}
    const int& breakTime() const    {return _nBreakTimeinSecs;}
          int& setBreakTime()       {return _nBreakTimeinSecs;}
    const int& Timer() const   {return _nBreakTimer;}
          int& setTimer()         {return _nBreakTimer;}
    const QString& experimenter() const {return _qstrName;}
          QString& setExperimenter()    {return _qstrName;}
    const QString& tel() const      {return _qstrTel;}
          QString& setTel()         {return _qstrTel;}  
    const vector<string>& conditionScript() const {return _vConditionScript;} 
          vector<string>& setConditionScript()    {return _vConditionScript;}
    const vector<int>& conditionNumScript() const {return _vConditionNumScript;} 
          vector<int>& setConditionNumScript()    {return _vConditionNumScript;}
    const int& trialDurationSecond() {return _nTrialDurationSecond;}
          int& setTrialDurationSecond() {return _nTrialDurationSecond;}
          void fullOutputFileName(int nTrial_,QString* pFullOutputFileName_) const;
          void disConnectFlyBox();
    
    bool IsTriggerDepressed();
    bool CheckForTriggerHelper();
    void CleanUp();
protected:
    string _strClassName;

    QString _qstrName;
    QString _qstrTel;
    static bool _bFlyBoxConnected;
    
    bool                _bFlyboxEnabled;

    string              _strOutputFileName;
    double              _dXPosition;
    int                 _nTexScale;
    int                 _nSceneType;
    
    int                _nCurrFrameIdx;
    int                _nTrialIdx;
    int                _nCurrControlOrder;
    int                _nDisturbanceOrder;
    int                _nSystemOutput;
    int                _nCheckFrameRate;
    int                _nBlockSize;
    int                _nBreakTimeinSecs;
    int                _nBreakTimer;
    int                _nTrialDurationSecond;

    float              _fFOVy;
    float			   _fFOVx;
    float              _fAspectRatio;
    float              _fNear;
    float              _fFar;
    float              _fScreenWidth;
    float              _fScreenHeight;
    double             _dEyeHeight;
    // script data
    CMatrix<double>    _mRunScript;

    vector<string>     _vConditionScript;
    vector<int>        _vConditionNumScript;
    // specify graphics colors 
    vector<double>     _vBackColor; 
    vector<double>     _vTexColor; 
    // texture file name
    vector<string>     _vstrTexFileName;
    // script file name
    QString            _strScriptFileName;


};
